home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / langwn23.zip / SAMPLE02.BAS < prev    next >
BASIC Source File  |  1993-02-11  |  36KB  |  1,010 lines

  1. '============================================================================
  2. '============================================================================
  3.  
  4. ' sample code 02 to demonstrate techniques for using LangWin.
  5. ' this sample has some complicated code, but if you take the time
  6. ' to understand it, you'll be able to better take advantage of LangWin.
  7.  
  8.  
  9. ' hit Shift+F5 to run this code.
  10.  
  11. ' you must start QuickBASIC as follows:  qb /ah /L langwin
  12. '    /L langwin parameter provides access to LangWin quicklib
  13. '    /ah parameter is needed to allow dynamic arrays > 64k.
  14.  
  15.  
  16. DECLARE SUB WinDemo01 () ' main subroutine to generate windows
  17. DECLARE SUB menu1 ()     ' process events for MENU1 selection
  18. DECLARE SUB Help1 ()     ' context sensitive help routine
  19. DECLARE SUB open1 ()     ' process user defined hotkey option (ctrl-o)
  20. DECLARE SUB about1 ()    ' process user defined hotkey option (atl-a)
  21. DECLARE SUB F2 ()        ' process user defined hotkey option (F2)
  22. ' subroutine to process button1 in main window
  23. DECLARE SUB MButton1 (box1%, field1%, wh%, ModTextWinNum%, ErrWinNum%)
  24.  
  25. DECLARE FUNCTION VidType% ()  ' used to determine type of monitor
  26.  
  27.  
  28. '$DYNAMIC  make all arrays dynamic
  29.  
  30. DEFINT A-Z
  31.  
  32. '$INCLUDE: 'LANGWIN.BI' ' TYPE, DECLARE and COMMON definitions for LangWin.
  33. '                         NOTE: LANGWIN.BI contains all definitions found
  34. '                               in QB.BI, so include for QB.BI is not needed.
  35.  
  36.  
  37.  
  38. CLEAR , , 5000   ' set stack at 5000 bytes
  39.  
  40.  
  41. '---------------------------------------------------------------
  42. ' first see if EGA or VGA monitor
  43. mm = VidType
  44. IF mm <> 3 AND mm <> 4 THEN
  45.     ' monitor is not EGA/VGA
  46.     ' take whatever actions necessary (error messages)
  47.     BEEP
  48.     PRINT "LangWin needs EGA or VGA, sorry ........"
  49.     END
  50. END IF
  51.  
  52.  
  53. '-----------------------------------------------------------------
  54. ' get attribute from current screen (row 1, col 1)
  55. ' so it can be restored upon exit
  56. OrigAttr = SCREEN(1, 1, 1)
  57.  
  58. '-------------------------------------------------------------------
  59. ' if WIDTH command is used, it must be placed before call to LangWinInit
  60. ' because code in LangWinInit extracts max rows/cols from screen and saves
  61. ' in global variables. if WIDTH is used after LangWinInit, the global
  62. ' variable will not be set correctly.
  63. WIDTH 80, 25
  64.  
  65. '----------------------------------------------------------------------
  66. ' these variables MUST be defined BEFORE call to LangWinInit.
  67. ' keep these as low as possible to conserve memory at run time.
  68. MaxWindows = 5       ' max simultaneous open windows
  69. MaxButtons = 35      ' max number of objects (incl text labels) active
  70. MaxTextLines = 40    ' max lines of text in any array of scrollable text
  71. MaxTextWins = 3      ' max # windows that can be open with scrollable text
  72.                      ' must be <= MaxWindows
  73.  
  74. LOCATE , , 0         ' start with hidden text cursor
  75.  
  76. '---------------------------------------------------------------------------
  77. ' LangWin only supports text mode. You MUST call the SCREEN 0 command BEFORE
  78. ' the call to LangWinInit. You can call SCREEN with a video page other than 0
  79. ' (i.e., SCREEN 0,,x,x   where x is a page number supported by your system).
  80. ' Code in LangWinInit will determine which video page you are using and save
  81. ' the value in a global variable for use by other LangWin routines. If you
  82. ' call SCREEN 0 after LangWinInit and change the original video page, you'll
  83. ' get unpredictable results (i.e., LangWin will write to the original video
  84. ' page). However, you can use other video pages for functions not associated
  85. ' with your LangWin windows; just be sure to set the video page back to the
  86. ' original value defined below.
  87.  
  88. SCREEN 0, , 0, 0        ' LangWin ONLY supports text mode
  89.                         ' You MUST call the SCREEN command BEFORE LangWinInit
  90.  
  91.  
  92. CALL LangWinInit     ' initialize (if mouse exists, it will be displayed)
  93.              
  94.                      ' if you get "subscript out of range" error while
  95.                      ' in this routine, be sure you called QB with /ah.
  96.                      ' then try reducing the value of MaxWindows.
  97.                      ' check the WIDTH command; reduce number of columns,
  98.                      ' and/or number of rows.
  99.  
  100. '-----------------------------------------------------------------------
  101. ' display "wallpaper"
  102.  
  103. IF HaveMouse THEN CALL HideMouseCursor  ' first hide mouse pointer
  104.  
  105. CLS
  106. CALL SetColor(8, 15)
  107. FOR i = 1 TO MaxRows
  108. LOCATE i, 1
  109. PRINT STRING$(80, 178);     ' can try 176, 177, or 178
  110. NEXT
  111.  
  112. IF HaveMouse THEN CALL ShowMouseCursor   ' display the mouse pointer
  113.  
  114. '====================================================================
  115.  
  116. ' this sample implements context sensitive help activated via the F1 key.
  117. ' (user defined hot keys, including F1, are defined in WinDemo01).
  118. ' in order for the routine that processes the F1 key (Help1)
  119. ' to determine the context (i.e., window and button with focus),
  120. ' the variable names used to store window numbers (returned by
  121. ' BlankWindow or OpenScrollWindow) and button handles (returned
  122. ' by the various "make" routines) must be DIM SHARED in the main module.
  123. ' those window numbers or button handles that do not need context
  124. ' sensitive help need not be SHARED.
  125. ' in addition, if you want context sensitive help to be displayed for
  126. ' a given window, then the code that processes actions (returned from
  127. ' WinEvent) in that window must detect the action associated with the
  128. ' F1 key and CALL Help1 (in the case of this sample code, the action for F1
  129. ' is 7 - see the user defined hot keys in WinDemo01).
  130.  
  131. ' main window
  132. DIM SHARED Main1, MainField1, MainBox1, MainButton1, MainMenu1
  133. ' window with modified text
  134. DIM SHARED ModTextWinNum
  135. ' menu1 window
  136. DIM SHARED MM1, mm1b1, mm1b2, mm1b3, mm1b4, mm1b5, mm1b6, mm1b7
  137. ' window opened to process selection from menu1
  138. DIM SHARED mm1ww
  139. ' windows corresponding to hot keys
  140. DIM SHARED about1w, f2w, open1w
  141.  
  142.  
  143. ' sample code to process windows
  144.   CALL WinDemo01
  145.  
  146.  
  147. '=====================================================================
  148.  
  149.  
  150. IF HaveMouse THEN HideMouseCursor    ' we're done with the mouse
  151.  
  152. bbb = (OrigAttr AND &HF0) \ 16  ' mask & shift to get original background
  153. fff = OrigAttr AND &HF          ' mask to get original foreground
  154.  
  155.  
  156. PALETTE                           ' restore original palette
  157. CALL SetColor(fff, bbb)           ' restore orig foreground/background
  158. CLS
  159. LOCATE , , 1                      ' make text cursor visible
  160.  
  161. END
  162.  
  163. REM $STATIC
  164. '
  165. ' this routine handles case where special hot key: alt-a selected
  166. ' (i.e., the "about" menu1 item)
  167. '
  168. ' i've only included sample code to open a modal window
  169. ' (with no error checking), display some text, and
  170. ' wait for close. production programs will have more details
  171. ' (which might not even require a window)
  172. '
  173. SUB about1
  174.  
  175. about1w = BlankWin(13, 3, 20, 30, 2, 15, 1, 0, 1, 2)
  176. d = ShowWinText(2, 2, 0, "ALT-A: About selected")
  177. ' loop waiting for a close action (1)
  178. DO
  179.     d = WinEvent(a)
  180.     IF a = 7 THEN CALL Help1  ' display help if selected
  181. LOOP UNTIL a = 1
  182. d = CloseWindow
  183.  
  184.  
  185. END SUB
  186.  
  187. '
  188. ' this routine handles case where special hot key: F2 selected
  189. ' (i.e., the "options" menu1 item)
  190. '
  191. ' i've only included sample code to open a modal window
  192. ' (with no error checking), display some text, and
  193. ' wait for close. production programs will have more details
  194. ' (which might not even require a window)
  195. '
  196. '
  197. SUB F2
  198.  
  199.  
  200. f2w = BlankWin(13, 3, 20, 30, 2, 15, 1, 0, 1, 2)
  201. d = ShowWinText(2, 2, 0, "F2: Options selected")
  202. ' loop waiting for a close action (1)
  203. DO
  204.     d = WinEvent(a)
  205.     IF a = 7 THEN CALL Help1  ' display help if selected
  206. LOOP UNTIL a = 1
  207. d = CloseWindow
  208.  
  209.  
  210. END SUB
  211.  
  212. '
  213. ' open a window with context sensitive help
  214. '
  215. ' all help text in this example is hard coded.
  216. '
  217. ' for a major project with many nested windows,
  218. ' you'll probably want to keep help text on disk,
  219. ' read it into an array, and then have this routine display the appropriate
  220. ' array entries based upon the context. i'll leave that
  221. ' as an exercise to the reader!!
  222. '
  223. '
  224. SUB Help1
  225.  
  226. ' CurWinPtr contains handle of window with focus when F1 pressed.
  227. ' need to determine corresponding window number from in WinNum().
  228. ' this must be done before help window is opened, which will change
  229. ' the value of CurWinPtr
  230.  
  231. wn = WinNum(CurWinPtr) ' get number of window with focus
  232. butfoc = WinParms(CurWinPtr, 16)' handle of button with focus
  233.  
  234. ' open a modal help window
  235. helpwin = BlankWin(1, 1, 11, 44, 3, 15, 2, 15, 1, 2)
  236.       
  237. ' first see if window opened successfully
  238. IF helpwin < 0 THEN
  239.    ' add code here to handle the case where window did not open
  240.    CLS
  241.    PRINT "helpwin BlankWin error: "; helpwin
  242.    END
  243. END IF
  244.          
  245. ' modal help window opened successfully,
  246.  
  247. ' determine the context
  248. ' first check the window number, then the button number
  249. SELECT CASE wn
  250.  
  251. CASE Main1      ' main menu
  252.     e = ShowWinText(1, 2, 14, "Help for main menu")
  253.    
  254.     ' which button had focus
  255.     SELECT CASE butfoc
  256.  
  257.     CASE MainField1
  258.         e = ShowWinText(2, 2, 14, "Input Field.")
  259.         e = ShowWinText(4, 2, 15, "Contents of input field will be inserted")
  260.         e = ShowWinText(5, 2, 15, "into all lines selected from scrollable")
  261.         e = ShowWinText(6, 2, 15, "text.")
  262.     CASE MainBox1
  263.         e = ShowWinText(2, 2, 14, "Check Box.")
  264.         e = ShowWinText(4, 2, 15, "Used as a toggle to allow selected text")
  265.         e = ShowWinText(5, 2, 15, "to be modified (when Button1 clicked).")
  266.         e = ShowWinText(6, 2, 15, "Check the box to enable modification.")
  267.    
  268.     CASE MainButton1
  269.         e = ShowWinText(2, 2, 14, "Button1.")
  270.         e = ShowWinText(4, 2, 15, "Used to initiate modification of selected")
  271.         e = ShowWinText(5, 2, 15, "text. Check Box acts as toggle, it must")
  272.         e = ShowWinText(6, 2, 15, "also be on to enable modification.")
  273.         e = ShowWinText(7, 2, 15, "Window will be opened with all text")
  274.         e = ShowWinText(8, 2, 15, "being modified.")
  275.     CASE MainMenu1
  276.         e = ShowWinText(2, 2, 14, "MENU1.")
  277.         e = ShowWinText(4, 2, 15, "Brings up a sub-menu with several")
  278.         e = ShowWinText(5, 2, 15, "options to choose from.")
  279.     CASE -1     ' no button had focus, only text
  280.         e = ShowWinText(2, 2, 14, "Scrollable Text")
  281.         e = ShowWinText(4, 2, 15, "Double click on any line of scrollable")
  282.         e = ShowWinText(5, 2, 15, "text. The selection character [X] will")
  283.         e = ShowWinText(6, 2, 15, "be toggled. All selected text will be")
  284.         e = ShowWinText(7, 2, 15, "modified (contents of input field added)")
  285.         e = ShowWinText(8, 2, 15, "when Button1 clicked & Check Box is set.")
  286.  
  287.     END SELECT   ' end of code that processes buttons in main win
  288.  
  289. CASE ModTextWinNum      ' modified text window
  290.     ' this window has no buttons
  291.     e = ShowWinText(1, 2, 14, "Help for Modified Text Window")
  292.     e = ShowWinText(4, 2, 15, "This window shows all selected text")
  293.     e = ShowWinText(5, 2, 15, "lines as modified. Closing this window")
  294.     e = ShowWinText(6, 2, 15, "will result in the main menu's text")
  295.     e = ShowWinText(7, 2, 15, "being updated and the selection toggle")
  296.     e = ShowWinText(8, 2, 15, "cleared.")
  297.  
  298. CASE MM1     ' menu1
  299.     e = ShowWinText(1, 2, 14, "Help for MENU1")
  300.     ' now determine which button had focus
  301.     SELECT CASE butfoc
  302.  
  303.     CASE mm1b1
  304.         e = ShowWinText(2, 2, 14, "Options ...")
  305.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  306.     CASE mm1b2
  307.         e = ShowWinText(2, 2, 14, "Files ...")
  308.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  309.     CASE mm1b3
  310.         e = ShowWinText(2, 2, 14, "Save As ...")
  311.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  312.     CASE mm1b4
  313.         e = ShowWinText(2, 2, 14, "Delete.")
  314.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  315.     CASE mm1b5
  316.         e = ShowWinText(2, 2, 14, "Open ...")
  317.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  318.     CASE mm1b6
  319.         e = ShowWinText(2, 2, 14, "Print ...")
  320.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  321.     CASE mm1b7
  322.         e = ShowWinText(2, 2, 14, "About ...")
  323.         e = ShowWinText(4, 2, 15, "Some help text for this button.")
  324.     CASE -1   ' no button had focus
  325.         e = ShowWinText(2, 2, 14, "(no item highlighted)")
  326.         e = ShowWinText(4, 2, 15, "Some general help text for MENU1 list.")
  327.  
  328.     END SELECT  ' end of code that processes buttons in menu1
  329.  
  330. CASE mm1ww  ' window opened to process selection from MENU1
  331.     e = ShowWinText(1, 2, 14, "Help for MENU1 selection window ...")
  332.     e = ShowWinText(4, 2, 15, "Some help text for this option.")
  333.  
  334. CASE about1w
  335.     e = ShowWinText(1, 2, 14, "Help for ALT-A About window ...")
  336.     e = ShowWinText(4, 2, 15, "Some help text for this option.")
  337. CASE f2w
  338.     e = ShowWinText(1, 2, 14, "Help for F2 Options window ...")
  339.     e = ShowWinText(4, 2, 15, "Some help text for this option.")
  340. CASE open1w
  341.     e = ShowWinText(1, 2, 14, "Help for CTRL-O Open window ...")
  342.     e = ShowWinText(4, 2, 15, "Some help text for this option.")
  343.  
  344.  
  345. END SELECT
  346.  
  347. ' put a title in window
  348. e = ShowTitle("**** HELP ****", 15, 4)
  349.  
  350. ' now wait for a close event
  351. DO
  352.     ww = WinEvent(aa)
  353. LOOP UNTIL aa = 1
  354. xx = CloseWindow
  355.  
  356.  
  357. END SUB
  358.  
  359. '
  360. '  process actions for Button1 in main menu
  361. '
  362. ' check state of box1.
  363. '
  364. ' if that box is set, then contents of MainField1 will be inserted into all
  365. ' selected scrollable text, a modal window will be opened (number returned in
  366. ' ModTextWinNum), and all modified text displayed in it.
  367. '
  368. ' if MainBox1 is not set, a modal error window is open (number returned in
  369. ' ErrWinNum).
  370. '
  371. ' if MainBox1 is set, but no text selected, a modal error window is opened
  372. ' (number returned in ErrWinNum).
  373. '
  374. '  input parms:
  375. '       box1:  handle of check box. status of this box is
  376. '              used to as a gate determine if selected scrollable text
  377. '              will be modified or not.
  378. '
  379. '       field1: handle of input field. if check box is set,
  380. '               contents of input field is inserted into
  381. '               all scrollable text that is selected in main window.
  382. '
  383. '       savindx:     index in SaveText of window's text
  384. '
  385. '  output parms:
  386. '       ModTextWinNum:  number of the modal window opened to display modified
  387. '                       text
  388. '       ErrWinNum:      number of modal window opened to display an err msg
  389. '
  390. SUB MButton1 (box1, field1, savindx, ModTextWinNum, ErrWinNum)
  391.  
  392. ' if check box is down
  393. ' then add contents of input field to all selected text;
  394. ' open a window and display all selected text.
  395.          
  396. IF ButtonsData(box1, 7) = 0 THEN ' see if box1 is down
  397.            
  398.     ' box1 was down, count selected text entries in scrollable text
  399.     c = 0
  400.     FOR i = 1 TO WinParms(CurWinPtr, 17)  ' only scan to end on non-null text
  401.     IF MID$(SaveText(savindx, i), 2, 1) = "X" THEN c = c + 1
  402.     NEXT
  403.            
  404.     ' if any text was selected, move entries and display
  405.     IF c > 0 THEN
  406.         ' there were some text entries selected
  407.  
  408.         ' create array for selected text
  409.         REDIM TempText(1 TO c) AS STRING  ' temp array
  410.         j = 1
  411.         'copy selected text to temp array
  412.         ' and add contents of second input field.
  413.         len2 = LEN(ButtonsText(field1))  ' len of 2nd input field
  414.         FOR i = 1 TO WinParms(CurWinPtr, 17)' only scan to end of non-null txt
  415.             IF MID$(SaveText(savindx, i), 2, 1) = "X" THEN 'find selected text entries
  416.                 len1 = LEN(SaveText(savindx, i))' len of text line
  417.                 x = len1 - len2 + 1 ' start of position to insert
  418.                 ' insert field1 into text line
  419.                 IF len2 > 0 THEN MID$(SaveText(savindx, i), x, len2) = ButtonsText(field1)
  420.                 TempText(j) = SaveText(savindx, i)  ' copy it to temp array
  421.                 j = j + 1   ' bump index to temp array
  422.             END IF
  423.         NEXT
  424.              
  425.         ' now open a modal window and display selected text lines
  426.         ModTextWinNum = OpenScrollWindow(10, 10, 20, 44, 1, 15, 2, 15, TempText(), 1, 1, 7, 30, 1, 2)
  427.         ERASE TempText   ' clear temp array to save sapce
  428.  
  429.         ' first see if window opened successfully
  430.         IF ModTextWinNum < 0 THEN
  431.            ' add code here to handle the case where window did not open
  432.            CLS
  433.            PRINT "ModTextWinNum OpenScrollWindow error: "; ModTextWinNum
  434.            END
  435.         END IF
  436.              
  437.         ' place title into window
  438.         e = MakeHorizLine(8, 2)
  439.         e = ShowWinText(9, 5, 15, "Close Window to Continue")
  440.         e = ShowTitle("MODIFIED TEXT", 15, 4)
  441.        
  442.         ' get an action from the modal window just opened
  443.         DO
  444.             ' modal window, no other window can be selected.
  445.             ' so no need to test window number generating the action.
  446.             ' the only valid action is a close (action = 1)
  447.             ' if text select action (3) then ignore it.
  448.             ' no buttons in window, so action 2 not possible.
  449.             wn = WinEvent(action)     ' get an event in modal win
  450.             IF action = 7 THEN CALL Help1  ' help key selected
  451.         LOOP UNTIL action = 1         ' wait for a close
  452.  
  453.         xx = CloseWindow  ' close the modal window
  454.      
  455.         ' now clear the "select" toggle from all text in main window
  456.         ' and redisplay window (with updated text).
  457.         ' after modal win has just been closed, prev win on the stack
  458.         ' is made current. we know the previous win was the main window,
  459.         ' since it was current when its button was selected to cause the
  460.         ' modal window to be opened and was just pushed on the stack.
  461.  
  462.         ' the following code operates on the current window.
  463.         ' it references CurWinPtr and subroutine ReShowPage
  464.         ' (which operates on text in current window).
  465.  
  466.         ' if we were not certain that main window would be made current
  467.         ' after the modal win is closed, we would have to make
  468.         ' sure the main window was made current before changing
  469.         ' its scrollable text.
  470.         ' the following code could be used to do this (assume we know that
  471.         ' the main window's number is in variable main1 - this could
  472.         ' be a global variable, or passed as a parm):
  473.         ' xx = IsWinOpen(main1,wh) ' returns TRUE/FALSE if win is open, also
  474.         '                          ' returns handle corresponding to main1
  475.         ' CALL NewFocusWindow(wh)  ' makes win with handle wh current
  476.  
  477.         FOR i = 1 TO WinParms(CurWinPtr, 17)' only scan to end of non-null txt
  478.             IF MID$(SaveText(savindx, i), 2, 1) = "X" THEN ' find selected text entry
  479.                 MID$(SaveText(savindx, i), 2, 1) = " "   ' clear the select
  480.             END IF
  481.         NEXT
  482.         CALL ReShowPage  ' re-display visible text in current (main) win
  483.  
  484.     ELSE
  485.         ' there were no text entries selected when button 1 was clicked
  486.         ' open a modal window and display a message.
  487.         ErrWinNum = BlankWin(10, 10, 20, 44, 4, 15, 2, 15, 1, 2)
  488.             
  489.         ' first see if window opened successfully
  490.         IF ErrWinNum < 0 THEN
  491.            ' add code here to handle the case where window did not open
  492.            CLS
  493.            PRINT "ErrWinNum BlankWin error: "; ErrWinNum
  494.            END
  495.         END IF
  496.            
  497.         ' modal error window opened successfully,
  498.         ' display some text in window
  499.         e = ShowWinText(5, 3, 15, "Close window to continue")
  500.         e = ShowTitle("NO SELECTED TEXT WAS FOUND", 15, 4)
  501.        
  502.        
  503.         ' this is a modal window with no selectable text or buttons.
  504.         ' wait for a close action (1)
  505.         DO
  506.             ww = WinEvent(aa)
  507.         LOOP UNTIL aa = 1
  508.         xx = CloseWindow
  509.       
  510.     END IF
  511.          
  512. ELSE
  513.           
  514.     ' box1 was not down when button1 was hit, display an error window
  515.   
  516.     ' open a modal window
  517.     ErrWinNum = BlankWin(10, 10, 20, 44, 4, 15, 2, 15, 1, 2)
  518.            
  519.     ' first see if window opened successfully
  520.     IF ErrWinNum < 0 THEN
  521.        ' add code here to handle the case where window did not open
  522.        CLS
  523.        PRINT "ErrWinNum BlankWin error: "; ErrWinNum
  524.        END
  525.     END IF
  526.           
  527.     ' show some text.
  528.     e = ShowWinText(2, 3, 15, "Click on Check Box1,")
  529.     e = ShowWinText(3, 3, 15, "before selecting Button1,")
  530.     e = ShowWinText(4, 3, 15, "to process all selected")
  531.     e = ShowWinText(5, 3, 15, "scrollable text.")
  532.     e = ShowWinText(7, 3, 15, "Close window to continue.")
  533.              
  534.     ' this is a modal window with no selectable text or buttons.
  535.     ' wait for a close action (1)
  536.     DO
  537.         ww = WinEvent(aa)
  538.     LOOP UNTIL aa = 1
  539.     xx = CloseWindow
  540.  
  541. END IF
  542.  
  543.  
  544. END SUB
  545.  
  546. '
  547. '  process actions for MENU1
  548. '
  549. '
  550. '
  551. SUB menu1
  552.  
  553. Handle = WinParms(CurWinPtr, 16) ' get handle of button clicked
  554. Col = ButtonsData(Handle, 3)' get column of button clicked
  555. ' open a window in same column (make it mode 2 - click off win closes it)
  556. MM1 = BlankWin(2, Col, 12, Col + 17, 7, 0, 1, 0, 1, 3)'
  557.   
  558. ' first see if window opened successfully
  559. IF MM1 < 0 THEN
  560.     ' add code here to handle the case where window did not open
  561.     CLS
  562.     PRINT "MM1 BlankWin error: "; MM1
  563.     END
  564. END IF
  565.  
  566. ' make buttons for MENU1
  567. ' save handles returned in individual variable names.
  568. ' when WinEvent indicates that a button was clicked,
  569. ' compare the clicked button's handle to each variable
  570. ' to determine which button was selected.
  571.  
  572. mm1b1 = MakePushButton(1, 1, 16, " Options...   F2", 0, 7, 0)
  573. mm1b2 = MakePushButton(2, 1, 16, " Files...       ", 0, 7, 0)
  574. mm1v1 = MakeHorizLine(3, 1)
  575. mm1b3 = MakePushButton(4, 1, 16, " Save As...     ", 0, 7, 0)
  576. mm1b4 = MakePushButton(5, 1, 16, " Delete         ", 0, 7, 0)
  577. mm1b5 = MakePushButton(6, 1, 16, " Open...  Ctrl-O", 0, 7, 0)
  578. mm1v2 = MakeHorizLine(7, 2)
  579. mm1b6 = MakePushButton(8, 1, 16, " Print...       ", 0, 7, 0)
  580. mm1b7 = MakePushButton(9, 1, 16, " About...  Alt-A", 0, 7, 0)
  581.             
  582.  
  583. ' wait for an event to occur in the MENU1 window
  584. DO
  585.     wn = WinEvent(action)
  586.   
  587.     SELECT CASE wn
  588.    
  589.     CASE MM1     ' main menu1
  590.        
  591.         ' now determine what type of event occurred in the main window
  592.         SELECT CASE action
  593.        
  594.         CASE 1      ' close
  595.             xx = CloseWindow
  596.             EXIT SUB   ' force an exit when menu1 is closed
  597.         CASE 2      ' text
  598.             'there is no scrollable text
  599.         CASE 3      ' buttons
  600.  
  601.             Hand1 = WinParms(CurWinPtr, 16)  ' get handle of button that was clicked
  602.   
  603.             ' for each button in MENU1 that can be clicked,
  604.             ' i've only included sample code to open a modal window
  605.             ' (with no error checking), display some text, and
  606.             ' wait for close. production programs will have more details
  607.             ' to process the meaning of each button (which might not
  608.             ' even require a window)
  609.  
  610.             SELECT CASE Hand1    ' select on handle of button that was clicked
  611.             CASE mm1b1   ' options
  612.                 CALL F2   ' this action has a hot key, call corresponding sub
  613.             CASE mm1b2   ' files
  614.                 mm1ww = BlankWin(13, 3, 20, 25, 2, 15, 1, 0, 1, 2)
  615.                 d = ShowWinText(2, 2, 0, "Files selected")
  616.             CASE mm1b3   ' save as
  617.                 mm1ww = BlankWin(13, 3, 20, 25, 2, 15, 1, 0, 1, 2)
  618.                 d = ShowWinText(2, 2, 0, "Save as selected")
  619.             CASE mm1b4   ' delete
  620.                 mm1ww = BlankWin(13, 3, 20, 25, 2, 15, 1, 0, 1, 2)
  621.                 d = ShowWinText(2, 2, 0, "Delete selected")
  622.             CASE mm1b5   ' open
  623.                 CALL open1 ' this action has a hot key, call corresponding sub
  624.             CASE mm1b6   ' print
  625.                 mm1ww = BlankWin(13, 3, 20, 25, 2, 15, 1, 0, 1, 2)
  626.                 d = ShowWinText(2, 2, 0, "Print selected")
  627.             CASE mm1b7   ' about
  628.                 CALL about1 'this action has a hot key, call corresponding sub
  629.                
  630.             END SELECT    ' end of code to process buttons
  631.        
  632.         ' user defined hot heys
  633.         CASE 4  ' F2 = options
  634.             CALL F2
  635.  
  636.         CASE 5  ' ctrl-o = open
  637.             CALL open1
  638.  
  639.         CASE 6  ' alt-a = about
  640.             CALL about1
  641.   
  642.         CASE 7  ' help = F1
  643.             CALL Help1
  644.  
  645.         END SELECT  ' end of code that processes actions in menu1 window
  646.  
  647.     CASE mm1ww  ' to handle one of the sample modal windows opened for
  648.                 ' menu1's buttons. for production programs, each button
  649.                 ' would probably have it's own unique window number.
  650.  
  651.         SELECT CASE action
  652.         CASE 1  'close
  653.             xx = CloseWindow
  654.         CASE 7  ' help key (F1)
  655.             ' since (for simplicity) i used the same variable (ww) for
  656.             ' every window opened in menu1, the help routine will
  657.             ' only display a generic message. in a production program,
  658.             ' each window opened in a menu will have a unique variable
  659.             ' name for its window number will be used by Help1
  660.             ' to provide more context sensitive help.
  661.             CALL Help1
  662.         END SELECT
  663.        
  664.     END SELECT   ' end of code that processes windows open by menu1
  665.  
  666. LOOP
  667.  
  668.  
  669. END SUB
  670.  
  671. '
  672. ' this routine handles case where special hot key: ctrl-o selected
  673. ' (i.e., the "open" menu1 item)
  674. '
  675. ' i've only included sample code to open a modal window
  676. ' (with no error checking), display some text, and
  677. ' wait for close. production programs will have more details
  678. ' (which might not even require a window)
  679. '
  680. SUB open1
  681.  
  682. open1w = BlankWin(13, 3, 20, 30, 2, 15, 1, 0, 1, 2)
  683. d = ShowWinText(2, 2, 0, "CTRL-O: Open selected")
  684. ' loop waiting for a close action (1)
  685. DO
  686.     d = WinEvent(a)
  687.     IF a = 7 THEN CALL Help1  ' display help if selected
  688. LOOP UNTIL a = 1
  689. d = CloseWindow
  690.  
  691.  
  692. END SUB
  693.  
  694. ' =====================================================
  695. '  returns type of video display
  696. '
  697. '  return values:
  698. '       1:  black/white    (could be EGA/VGA with monochrome)
  699. '       2:  CGA   (with color)
  700. '       3:  EGA   (with color)
  701. '       4:  VGA   (with color)
  702. '       5:  MCGA  (with color)
  703. '      99:  other
  704. '
  705. FUNCTION VidType
  706.  
  707. ' quick & dirty, check &h463
  708. DEF SEG = 0
  709. IF PEEK(&H463) = &HB4 THEN     ' see if monochrome
  710.     VidType = 1
  711.     EXIT FUNCTION
  712. END IF
  713. DEF SEG
  714.  
  715. ' first try int 10h, function 1Ah
  716.  
  717. InRegs.ax = &H1A00
  718. CALL INTERRUPTX(&H10, InRegs, OutRegs)
  719. IF (OutRegs.ax AND &HFF) = &H1A THEN    ' see if int 10h, funct 1Ah supported
  720.     code = (OutRegs.bx AND &HFF)  ' get display code
  721.     SELECT CASE code
  722.     CASE 1      ' MDA
  723.         VidType = 1
  724.     CASE 2      ' CGA
  725.         VidType = 2
  726.     CASE 4      ' EGA color
  727.         VidType = 3
  728.     CASE 5      ' EGA b/w
  729.         VidType = 1
  730.     CASE 7      ' VGA b/w
  731.         VidType = 1
  732.     CASE 8      ' VGA color
  733.         VidType = 4
  734.     CASE 10     ' MCGA color
  735.         VidType = 5
  736.     CASE 11     ' MCGA b/w
  737.         VidType = 1
  738.     CASE ELSE
  739.         VidType = 99    ' other
  740.     END SELECT
  741.     EXIT FUNCTION
  742.  
  743. ELSE
  744.     ' now try int 10h, function 12h, sub-function 10h
  745.     InRegs.ax = &H1200
  746.     InRegs.bx = &H10
  747.     CALL INTERRUPTX(&H10, InRegs, OutRegs)
  748.     IF (OutRegs.bx AND &HFF00) = 1 THEN     ' see if monochrome
  749.         VidType = 1
  750.         EXIT FUNCTION
  751.     END IF
  752.  
  753.     IF (OutRegs.bx AND &HFF) <> &H10 THEN   ' see if BL reg changed
  754.         VidType = 3    ' EGA (not sure why it couldn't be VGA too!)
  755.         EXIT FUNCTION
  756.     END IF
  757.  
  758.     VidType = 99      ' other (probably CGA or MDA)
  759.  
  760. END IF
  761.  
  762. END FUNCTION
  763.  
  764. '===========================================================================
  765. '
  766. ' demonstration of windows using LangWin's routines
  767. '
  768. ' sample functions performed:
  769. '
  770. ' scrollable text is selected/un-selected by double clicking on each line.
  771. ' when button1 is selected, check box (immediately to right
  772. ' of button1) is tested. if it is down, then contents of input
  773. ' field is inserted at end of all selected text lines, and all selected text
  774. ' are displayed in a window. closing the window will un-select all text.
  775. '
  776. ' this demonstrates the technique for displaying a selectable list in the
  777. ' scrollable window, allowing user to enter data in an input field,
  778. ' and using the combination of a check box setting and push button
  779. ' to take action on the items selected in the list.
  780. '
  781. ' other techniques demonstrated include creating a menu bar across top
  782. ' of window, opening windows with additional menu choices, user defined
  783. ' hot keys, and a routine to handle context sensitive help.
  784. '
  785. SUB WinDemo01
  786.  
  787.  
  788. ' create some scrollable text.
  789. ' in your production program, this could be anything needed to be
  790. ' scrolled and selected (i.e., help text, lists, options, etc.)
  791. ' the sample text is preceeded with the following characters: [ ]
  792. ' these are not necessary for scrollable text in general. they will be used
  793. ' to demonstrate how to handle selectable text in a scrollable list.
  794.  
  795. DIM Text2(1 TO 30) AS STRING
  796. FOR i = LBOUND(Text2) TO UBOUND(Text2)
  797. Text2(i) = "[ ] " + STR$(i) + "- some scrollable text."
  798. NEXT
  799.  
  800. ' open an info only window
  801. ' mode type 4 - there will be no code to handle events
  802. ' in this window (i.e., no events, including close, are processed).
  803. ' no shadow, and unmovable.
  804. ' this type of window can display permanent instructions, etc.
  805. ' this window WILL need to be closed before terminating the program
  806. inf = BlankWin(18, 10, 21, 30, -5, 15, 1, 15, 0, -4)
  807. d = ShowWinText(1, 2, 15, "Info Only Window")
  808.  
  809.  
  810. ' open an unmovable scrollable text window as main menu
  811. Main1 = OpenScrollWindow(1, 2, 14, 68, 9, 15, 2, 15, Text2(), 2, 1, 12, 30, 1, 1)
  812.  
  813. ERASE Text2  ' to save space
  814.  
  815. ' first see if window opened successfully
  816. IF Main1 < 0 THEN
  817.     ' add code here to handle the case where window did not open
  818.     CLS
  819.     PRINT "Main1 OpenScrollWindow error: "; Main1
  820.     END
  821. END IF
  822.  
  823. ' window opened successfully, put stuff in it
  824.  
  825. ' text and lines
  826. ' to make this example simple, i did not check for non-zero
  827. ' return codes from functions that display lines and text.
  828. vn$ = GetVerNum$    ' get version number
  829. e = ShowWinText(1, 40, 15, "LangWin Ver: " + vn$)  ' heading
  830. e = MakeVertLine(32, 1)                            ' wertical line
  831. e = ShowWinText(12, 38, 13, "Input Field:")       ' input field label
  832. e = ShowWinText(3, 42, 11, "BUTTONS")              ' buttons heading
  833. e = ShowWinText(3, 55, 11, "CHECK")                ' check boxes heading
  834. e = MakeBox(2, 38, 9, 51, 1, 15)                   ' box around buttons
  835. e = MakeBox(2, 52, 9, 62, 1, 15)                   ' box around check boxes
  836. e = ShowWinText(13, 0, 13, "F1 = help")               ' help hot key
  837.  
  838.  
  839. ' input fields, check boxes, and push buttons in Main window.
  840. ' the handles returned by the "make" functions for fields and boxes are saved
  841. ' in variable names. these are used later to determine state of check box
  842. ' and contents of input field.
  843.  
  844. ' input fields
  845. MainField1 = MakeInputField(12, 52, 10, " *LangWin*", 11, 0)'"LangWin" is default
  846. ' check boxes
  847. MainBox1 = MakeCheckBox(5, 55, 15, 13, CheckOff)  ' initially off
  848. ' buttons
  849. MainButton1 = MakePushButton(5, 40, 10, "Button1", 15, 4, 1)
  850. Look1 = MakePushButton(7, 40, 10, "Look", 15, 4, 1)
  851.  
  852.  
  853. ' menu bar buttons
  854. MainMenu1 = MakePushButton(0, 1, 8, "MENU1", 0, 7, 0)
  855. MainMenu2 = MakePushButton(0, 9, 8, "MENU2", 0, 7, 0)
  856. MainMenu3 = MakePushButton(0, 17, 8, "MENU3", 0, 7, 0)
  857. MainMenu4 = MakePushButton(0, 25, 8, "MENU4", 0, 7, 0)
  858. MainMenu5 = MakePushButton(0, 33, 8, "MENU5", 0, 7, 0)
  859. MainMenu6 = MakePushButton(0, 41, 8, "MENU6", 0, 7, 0)
  860. MainMenu7 = MakePushButton(0, 49, 8, "MENU7", 0, 7, 0)
  861. MainMenu8 = MakePushButton(0, 57, 8, "MENU8", 0, 7, 0)
  862.  
  863. ' redefine some additional global Hot Keys
  864. REDIM UserHotKeys(0 TO 4, 1 TO 2)
  865. ' each key is defined by its ascii value and WinEvent return code
  866. UserHotKeys(1, 1) = -60 ' F2 key  (options)
  867. UserHotKeys(1, 2) = 4   ' WinEvent action=4
  868. UserHotKeys(2, 1) = 15  ' ctrl-o key  (open)
  869. UserHotKeys(2, 2) = 5   ' WinEvent action=5
  870. UserHotKeys(3, 1) = -30 ' alt-a key   (about)
  871. UserHotKeys(3, 2) = 6  '  WinEvent action=6
  872. UserHotKeys(4, 1) = -59 ' F1 key      (help)
  873. UserHotKeys(4, 2) = 7  '  WinEvent action=7
  874.  
  875.  
  876. ' MAIN LOOP
  877. ' as long as any win is open
  878. ' wait for an event in any window, then process it
  879.  
  880. DO       ' infinite loop. when main win closed, exit subroutine
  881.     ' wait for an event
  882.     ' win number (wn) and event code (action) returned
  883.     wn = WinEvent(action)
  884.  
  885.     ' test window number to see which window was current when event occurred
  886.     SELECT CASE wn
  887.  
  888.     CASE Main1      ' main window
  889.         seltxt = WinParms(CurWinPtr, 15)  ' get index of selected text
  890.         savindx = WinParms(CurWinPtr, 18)   ' index in SaveText scroll text
  891.        
  892.         ' now determine what type of event occurred in the main window
  893.         SELECT CASE action
  894.         CASE 1      ' close
  895.             xx = CloseWindow
  896.             ' since info win is mode 4, we know it's still open
  897.             ' (it cannot be selected or closed by user).
  898.             z = IsWinOpen(inf, wh)  ' get handle of info win
  899.             CALL NewFocusWindow(wh) ' give focus to info win
  900.                              ' since it's the last win open, it
  901.                              ' should already have focus, this is just
  902.                              ' a double check.
  903.             xx = CloseWindow  ' close the info window
  904.             EXIT SUB   ' force an exit when main win is closed
  905.         CASE 2      ' text
  906.             ' if a line of scrollable text in main win is selected,
  907.             ' toggle a selection character in the text.
  908.      
  909.             ' if MainButton1 in main win is later hit & MainBox1
  910.             ' is down, then all selected text will be processed (contents of
  911.             ' MainField1 will be inserted into these lines, a window
  912.             ' opened, and all modified text displayed).
  913.             ' this demonstrates how one can select entries from a scrollable
  914.             ' list of text, and later process them based upon other
  915.             ' button events.
  916.  
  917.             'toggle selection character
  918.             IF MID$(SaveText(savindx, seltxt), 2, 1) = "X" THEN
  919.                 MID$(SaveText(savindx, seltxt), 2, 1) = " "  ' un-select
  920.             ELSE
  921.                 MID$(SaveText(savindx, seltxt), 2, 1) = "X"   ' select
  922.             END IF
  923.             CALL ReShowText               ' re-display text in win
  924.        
  925.         CASE 3      ' button
  926.             ' all button handles returned from the "make" routine have been
  927.             ' saved in variable names.
  928.             ' use these variables to determine which button in main window
  929.             ' was hit
  930.        
  931.             bhandle = WinParms(CurWinPtr, 16) ' get handle of button clicked
  932.            
  933.             SELECT CASE bhandle    ' process the button
  934.            
  935.             CASE MainButton1  ' button1
  936.                 ' call subroutine that will check state of MainBox1.
  937.                 ' if that box is set, then contents of MainField1 will
  938.                 ' be inserted into all selected scrollable text, a modal
  939.                 ' window will be opened (number returned in ModTextWinNum),
  940.                 ' and all modified text displayed in it.
  941.                 ' if MainBox1 is not set, a modal error window is open
  942.                 ' (number returned in ErrWinNum).
  943.                 ' if MainBox1 is set, but no text selected, a modal
  944.                 ' error window is opened (number returned in ErrWinNum).
  945.                
  946.                 CALL MButton1(MainBox1, MainField1, savindx, ModTextWinNum, ErrWinNum)
  947.             
  948.             CASE MainMenu1
  949.                 CALL menu1
  950.            
  951.             ' no code for selecting other menu buttons.
  952.             ' i'll leave that for you to experiment with.
  953.             CASE MainMenu2
  954.             CASE MainMenu3
  955.             CASE MainMenu4
  956.             CASE MainMenu5
  957.             CASE MainMenu6
  958.             CASE MainMenu7
  959.             CASE MainMenu8
  960.            
  961.             CASE Look1     ' show some instructions
  962.                 ' open modal window, don't bother checking for error
  963.                 l1w = BlankWin(2, 20, 23, 77, 1, 15, 2, 15, 1, 2)
  964.           
  965.                 ' display some text in window
  966.                 e = ShowWinText(2, 2, 15, "You can try 2 tasks:")
  967.                 e = ShowWinText(4, 2, 15, "1) A. Select some scrollable text (double click).")
  968.                 e = ShowWinText(5, 2, 15, "   B. Click check box to the right of Button1.")
  969.                 e = ShowWinText(6, 2, 15, "   C. Change the text in the input field.")
  970.                 e = ShowWinText(7, 2, 15, "   D. Click Button1.")
  971.                 e = ShowWinText(9, 2, 15, "   You'll see a window with all selected text.")
  972.                 e = ShowWinText(10, 2, 15, "   Input field will be inserted at end of text.")
  973.                 e = ShowWinText(11, 2, 15, "   When you close that window, scrollable text")
  974.                 e = ShowWinText(12, 2, 15, "   in main window is permanently updated.")
  975.                 e = ShowWinText(15, 2, 15, "2) Click on MENU1.")
  976.                 e = ShowWinText(16, 2, 15, "   You'll get a sub-menu with other options.")
  977.                 e = ShowWinText(17, 2, 15, "   You can click on options, or use Hot Keys.")
  978.                 e = ShowWinText(20, 2, 14, "CLOSE WINDOW TO CONTINUE")
  979.                 e = ShowTitle("INSTRUCTIONS", 15, 4)
  980.     
  981.             END SELECT   ' end of code to process buttons in main menu
  982.        
  983.         ' user defined hot keys
  984.         CASE 4  ' F2 = options
  985.             CALL F2
  986.  
  987.         CASE 5  ' ctrl-o = open
  988.             CALL open1
  989.  
  990.         CASE 6  ' alt-a = about
  991.             CALL about1
  992.  
  993.         CASE 7  ' F1 = help
  994.             CALL Help1
  995.  
  996.         END SELECT  ' end of code that processes actions in main win
  997.  
  998.     CASE l1w  ' look window (instructions)
  999.         ' this is a modal window, only the close action will be processed
  1000.         IF action = 1 THEN xx = CloseWindow
  1001.  
  1002.    
  1003.     END SELECT  ' end of code that processes events in open windows
  1004.  
  1005.  
  1006. LOOP
  1007.  
  1008. END SUB
  1009.  
  1010.